package com.gfm.story.controller;

import com.gfm.story.entity.base.PageBean;
import com.gfm.story.entity.story.Category;
import com.gfm.story.service.story.CategoryService;
import com.gfm.story.util.ParamUtil;
import com.sun.org.apache.xpath.internal.operations.Mod;
import io.swagger.annotations.Api;
import javafx.geometry.Pos;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * @BelongsProject: story
 * @BelongsPackage: com.gfm.story.controller
 * @Author: Administrator
 * @CreateTime: 2019-06-03 16:16
 * @Description: ${Description}
 */
@Api(value = "小说类别接口")
@Controller
@RequestMapping(value = "/Category")
public class CategoryController {

    @Resource
    private CategoryService categoryService;

    /**
     * 进入分类页面
     * @return
     */
    @RequestMapping("loadFl")
    public String getFl(){
        return "fl";
    }

    /**
     * 获取小说类别
     * @return
     */
    @RequestMapping("/getCategory")
    public String getCategory(ModelMap modelMap){
        List<Category> list = categoryService.getCategory();
        modelMap.put("categort",list);
        return "fl";
    }

    @RequestMapping("/getBookByCategoryId")
    public String getBookByCategoryId(Long CategoryId, ModelMap modelMap, PageBean pageBean, HttpServletRequest request) throws Exception {
        Map<String, Object> map = ParamUtil.getParameterMap(request);
        if (null != CategoryId) {
            map.put("CategoryId", CategoryId);
        }
            map.put("start", pageBean.getStart());
            map.put("pageSize", pageBean.getRows());
            modelMap.put("CategoryBook",categoryService.getBookByCategoryId(map,pageBean.getPage()));
            modelMap.put("CategoryId",CategoryId);
        return "fl";
    }





}
